{extend name="common@base" /}
{block name="content"}
<style>
  .input-group-addon {
    cursor: pointer;
  }
</style>

<section class="content">
  <div class="row">
    <div class="col-xs-12">
      <form action="" method="post" class="form">
        <div class="box box-primary">
          <div class="box-body">
            <div class="form-group">
              <label for="">类型
                {:form_dropdown('form[type]',$qType,$row.type,'class="form-control"')}</label>
            </div>
            <div class="form-group">
              <label for="">题目
                <script id="container" name="form[content]" type="text/plain">{$row.content}</script>
              </label>
            </div>
            <div class="form-group" id="answers">
              <label for="">选项</label>
              <div class="form-group" v-for="(item,index) in items.cur">
                <div class="input-group">
                  <span class="input-group-addon" v-on:click="selectLine(index)"
                        v-bind:class="{'label-success':right==index}">
                    {{index+1}}、<i class="fa fa-check"></i></span>
                  <input type="text" name="form[answer][{$k}]" v-model="items.cur[index]" class="form-control">
                  <span class="input-group-addon label-danger">
                    <i class="fa fa-close " v-on:click="delLine(index)"></i></span>
                </div>
              </div>
              <input type="hidden" name="form[right]" v-model="right">
              <a href="javascript:;" class="btn_line btn btn-default btn-xs" v-on:click="addLine">插入一行</a>

            </div>
            <div class="form-group">
            </div>
          </div>
          <div class="box-footer">
            <div>
              <button class="btn btn-primary js-ajax-submit" type="submit">保存</button>
              <a href="javascript:history.back()" class="btn btn-default">返回</a>
            </div>
          </div>
        </div>
      </form>
    </div>
  </div>
</section>
{/block}
{block name="page_script"}
<script>
  require(["vue",], function (Vue) {
    var answers = new Vue({
      el: "#answers",
      data: {
        click: 0,
        right: {$right},
        right2: 2,
        answerSelect: null,
        items: {cur: {$answers}}
      },
      created: function () {

      },
      watch: {},
      methods: {
        getIndex: function ($index) {
          this.click = $index;
        },
        addLine: function (e) {
          this.items.cur.push("");
        },
        selectLine: function ($index) {
          this.right = $index;
        },
        delLine: function ($index) {
          if(this.right==$index){
            js_alert('您正在删除一个正确答案，请先选择其他正确答案后再删除这个选项。');
            return false;
          }else if(this.right>$index){
            this.right-=1;
          }
          this.items.cur.splice($index, 1);
        }
      },
    });
  });
  require(["layer_config", "ajaxForm",], function (layer) {

  });
  require(["ueditor"], function (ueditor) {
    var ue = ueditor.getEditor('container', {
      UEDITOR_HOME_URL: "__STATIC__/ueditor/",
      autoHeight: false,
      initialFrameHeight: 220
    });
    ue.ready(function () {
      //ue.execCommand('drafts');
    });
  });
</script>
{/block}





